/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cr.ac.una.sive.managed;

import cr.ac.una.sive.entidad.Color;
import cr.ac.una.sive.entidad.Vehiculo;
import cr.ac.una.sive.entidadLocal.ColorLocal;
import cr.ac.una.sive.sessionbean.ColorFacade;
import cr.ac.una.sive.sessionbean.ColorFacadeLocal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

/**
 *
 * @author claribel
 */
@ManagedBean
@RequestScoped
public class ColorFacadeManaged {    
    @EJB(mappedName = "ejb/ColorFacade")
    private ColorFacadeLocal colorFacade;
    
    private Integer id_color;
    private String nombre;
    private Set<Vehiculo> vehiculos = new HashSet<Vehiculo>(0);
    private ArrayList listaColores = new ArrayList();
    

    private ColorLocal colorLocal = new ColorLocal();

    public ColorFacadeManaged(ColorFacadeLocal colorFacade) {
        this.colorFacade = colorFacade;
    }

    
    public ColorFacadeManaged() {
       
    }

   
    public ColorLocal getColorLocal() {
        return colorLocal;
    }

    public void setColorLocal(ColorLocal colorLocal) {
        this.colorLocal = colorLocal;
    }

    public Integer getId_color() {
        return id_color;
    }

    public void setId_color(Integer id_color) {
        this.id_color = id_color;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public Set<Vehiculo> getVehiculos() {
        return vehiculos;
    }

    public void setVehiculos(Set<Vehiculo> vehiculos) {
        this.vehiculos = vehiculos;
    }

    public void setListaColores(ArrayList listaColores) {
        this.listaColores = listaColores;
    }
    
    
    /**
     * Creates a new instance of ColorFacadeManaged
     */
    public ColorFacadeManaged(String nombre, Integer id_color,Set <Vehiculo> vehiculos) {
         this.nombre = nombre;
         this.id_color = id_color;
         this.vehiculos = vehiculos;
    }
    
      public ArrayList getListaColores() {        
       
        List<Color> colores = colorFacade.findAll();
        listaColores.clear();

        for(int i=0; i<colores.size(); i++)
        {
            Color col = new Color();
            col = (Color)colores.get(i);
           
            listaColores.add(new SelectItem(col,col.getNombre()));
        }      
       
        return listaColores;
    }
}   